![]() |
PATH![]() |
![]() ![]() |
By default, AppleScript waits one minute for a response before stopping execution of application and scripting addition commands that are sent to other applications. A With Timeout statement lets you change how long AppleScript waits.
with timeout [ of ] integer second[s]
[ statement ]...
end [ timeout ]
integer is an integer that specifies the amount of time, in seconds, AppleScript allows for each application command or command addition contained in the With Timeout statement that is sent to any application other than the current one.
The following script starts the Finder on a task that may take a long time to complete. First it creates 40 folders, then it opens them, then it starts to close them, using a With Timeout statement to interrupt script execution one second after starting the Close operation. If the With Timeout statement generates an error, the error section of the Try statement calls the Beep scripting addition command and also writes "beep" to the Script Editor's Event Log window.
tell application "Finder"
repeat 40 times
make new folder at startup disk
end repeat
open (every folder of startup disk whose name contains "untitled")
try
with timeout of 1 second
close (every folder of startup disk ¬
whose name contains "untitled")
end timeout
on error
--Just beep and notify Script Editor's Event Log window.
beep
log ("beep")
end try
end tell